<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<meta charset="utf-8">
<head th:include="include :: header('修改栏目')"></head>
<body class="white-bg">
	<div class="wrapper wrapper-content animated fadeInRight ibox-content">
		<form class="form-horizontal m" id="form-column-edit"
			th:object="${cmsColumn}">
			<input id="treeId" name="parentId" type="hidden"
				th:field="*{parentId}" />
			<div class="form-group">
				<label class="col-sm-3 control-label ">上级栏目：</label>
				<div class="col-sm-8">
					<div class="input-group">
						<input class="form-control" type="text"
							onclick="selectColumnTree()" id="treeName" readonly="true"
							th:value="${parentName}"> <span class="input-group-addon"><i
							class="fa fa-search"></i></span>
					</div>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">栏目类型：</label>
				<div class="col-sm-8">
					<label class="radio-box"> <input type="radio" name="parent"
						value="1" th:field="*{parent}" /> 目录
					</label> <label class="radio-box"> <input type="radio"
						name="parent" value="0" th:field="*{parent}" /> 导航
					</label>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">栏目名称：</label>
				<div class="col-sm-8">
					<input class="form-control" type="text" name="columnName"
						th:field="*{columnName}" id="columnName" required>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">栏目Id</label>
				<div class="col-sm-8">
					<input class="form-control" type="text" name="columnId"
						id="columnId" th:field="*{columnId}" readonly>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">栏目地址：</label>
				<div class="col-sm-8">
					<input id="url" name="columnUrl" th:field="*{columnUrl}"
						class="form-control" type="text">
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">权限标识：</label>
				<div class="col-sm-8">
					<input id="perms" name="perms" th:field="*{perms}"
						class="form-control" type="text">
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">打开方式：</label>
				<div class="col-sm-8" id="op">
					<label class="radio-box" title=""> <input name="openType"
						type="radio" th:field="*{openType}" value="1" />新窗口
					</label> <label class="radio-box" title=""> <input name="openType"
						type="radio" th:field="*{openType}" value="2" /> 父窗口
					</label> <label class="radio-box" title=""> <input name="openType"
						type="radio" th:field="*{openType}" value="3" /> 当前窗口
					</label> <label class="radio-box" title=""> <input name="openType"
						type="radio" th:field="*{openType}" value="4" /> 顶层窗口
					</label>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">栏目排序：</label>
				<div class="col-sm-8">
					<input class="form-control" type="text" name="orderNo"
						th:field="*{orderNo}" required>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">栏目备注：</label>
				<div class="col-sm-8">
					<input class="form-control" type="text" name="remark"
						th:field="*{remark}">
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">栏目图标：</label>
				<div class="col-sm-8">
					<input id="icon" name="columnIcon" class="form-control"
						th:field="*{columnIcon}" type="text" placeholder="选择图标">
					<div class="ms-parent" style="width: 100%;">
						<div class="icon-drop animated flipInX"
							style="display: none; max-height: 200px; overflow-y: auto">
							<div data-th-include="system/menu/icon"></div>
						</div>
					</div>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">栏目状态：</label>
				<div class="col-sm-8">
					<div class="radio-box" th:each="dict : ${@dict.getType('cms_cat_visible')}">
						<input type="radio" th:id="${dict.dictCode}" name="visible" th:value="${dict.dictValue}"  th:field="*{visible}">
						<label th:for="${dict.dictCode}" th:text="${dict.dictLabel}"></label>
					</div>
				</div>
			</div>
		</form>
	</div>
	<div th:include="include::footer"></div>
	<script>
        var prefix = ctx + "cms/column";
        
        $("#form-column-edit").validate({
        	rules:{
        		openType:{
        			required:true,
        		},
        		isParent:{
        			required:true,		
        		},
        		orderNo:{
        			digits:true
        		},
        		columnUrl:{
        			remote: {
                        url: prefix + "/checkColumnUrlUnique",
                        type: "post",
                        dataType: "json",
                        data: {
							"parentId": function() {
								return $("input[name='parentId']").val();
							},
                        	"columnUrl" : function() {
                                return $.common.trim($("input[name=columnUrl]").val());
                            },"columnId" : function() {
                                return $.common.trim($("input[name=columnId]").val());
                            }       
                        },
                        dataFilter: function(data, type) {
                        	return $.validate.unique(data);
                        }
        			}
        		},
        		columnName:{
        			required:true,
        			remote: {
                        url: prefix + "/checkColumnNameUnique",
                        type: "post",
                        dataType: "json",
                        data: {
                        	"parentId": function() {
		                		return $("input[name='parentId']").val();
		                    },
                        	"columnName" : function() {
                                return $.common.trim($("#columnName").val());
                            },
                            'columnId':$("#columnId").val()             
                        },
                        dataFilter: function(data, type) {
                        	return $.validate.unique(data);
                        }
                    }
        		},
        	},
        	messages: {
                "columnName": {
                    remote: "导航名已存在"
                },
                "columnUrl": {
                    remote: "导航路径已存在"
                }
            },
            focusCleanup: true
        });
        
        function submitHandler() {
	        if ($.validate.form()) {
	            $.operate.save(prefix + "/edit", $('#form-column-edit').serialize());
	        }
	    }

        $(function() {
        	$("input[name='columnIcon']").focus(function() {
                $(".icon-drop").show();
            });
        	$("#form-column-edit").click(function(event) {
        	    var obj = event.srcElement || event.target;
        	    if (!$(obj).is("input[name='columnIcon']")) {
        	    	$(".icon-drop").hide();
        	    }
        	});
        	$(".icon-drop").find(".ico-list i").on("click", function() {
        		$('#icon').val($(this).attr('class'));
            });
        	$('input[name="parent"]').on('ifChecked', function(event){    		
        		var isParent = $(event.target).val();
        		if (isParent == 1) {
                    $("#url").parents(".form-group").hide();
                    $("#op").parents(".form-group").hide();       
                } else if (isParent == 0) {
                	$("#url").parents(".form-group").show();       
                    $("#op").parents(".form-group").show();
                } 
        	});  
        });

        /*栏目管理-编辑-选择栏目树*/
        function selectColumnTree() {
        	var treeId = $("#treeId").val();
        	var menuId = treeId > 0 ? treeId : 1;
        	var url = prefix + "/selectColumnTree/" + menuId;
			var options = {
				title: '栏目选择',
				width: "380",
				url: url,
				callBack: doSubmit
			};
			$.modal.openOptions(options);
		}

		function doSubmit(index, layero){
			var body = layer.getChildFrame('body', index),treeId=body.find('#treeId').val();
			if( treeId===$("input[name='columnId']").val()){
				layer.confirm('不能选择自己为父节点', {
					btn: ['重新选择'] //按钮
				}, function(c){
					layer.close(c);
				});
			}
			else{
				$("#treeId").val(treeId);
				$("#treeName").val(body.find('#treeName').val());
				layer.close(index);
			}

		}
    </script>
</body>
</html>
